<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>机蜂超市仓库管理后台</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/stylesheets/base.css">
    <script src="/layui/layui.js"></script>
    <script src="/javascripts/jquery.js"></script>
    <script src="/javascripts/ajax.js"></script>
    <style>
        .layui-icon{
            display: inline-block;
            width: 20px;
            margin-right: 10px;
        }
    </style>
</head>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">
            <a href="/welcome" onclick="homeClick()" target="content" style="color: #cccccc">仓库管理后台</a>
        </div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <img id="avatar" src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img">
                    <span id="nickname">tester</span>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" onclick="showUserWin()">个人信息</a></dd>
                    <dd><a href="javascript:;" onclick="showPasswordWin()">修改密码</a></dd>
                    <dd><a href="javascript:;" onclick="logout()">退出系统</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree " lay-filter="test">
                <li class="layui-nav-item" id="userMenu">
                    <a href="/userinfo" target="content"><i class="layui-icon layui-icon-group"></i>用户管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/store" target="content"><i class="layui-icon layui-icon-component"></i>仓库管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/supplier" target="content"><i class="layui-icon layui-icon-transfer"></i>供货商管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/goods" target="content"><i class="layui-icon layui-icon-template-1"></i>商品管理</a>
                </li>
                <li class="layui-nav-item">
                    <a class="" href="javascript:;"><i class="layui-icon layui-icon-form"></i>记录管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/apply" target="content">申请记录</a></dd>
                        <dd><a href="/records" target="content">操作记录</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-body" style="padding: 15px">
        <iframe name="content" width="100%" height="90%" frameborder="no" src="/welcome"></iframe>
    </div>
    <div class="layui-footer">
        <!-- 底部固定区域 -->
        底部固定区域
    </div>
</div>

<script>
$(function () {
    const element = layui.element;
    getLoginInfo();
})
function homeClick(){
    $(".layui-nav-item").removeClass("layui-this")
}
function getLoginInfo() {
    ajax.get("/userinfo/info").then(userinfo=>{
        $("#nickname").text(userinfo.nickname)
        $("#avatar").prop("src",userinfo.avatar)
        if(userinfo.role === 1){
            $("#userMenu").show();
        }else{
            $("#userMenu").hide();
        }
        window.loginInfo = userinfo
    })
}
function showUserWin() {
    layer.open({
        type:2,
        content:"/userinfo/edit?id="+window.loginInfo.id,
        area:["500px","500px"]
    })
}
function showPasswordWin() {
    layer.open({
        type:2,
        content:"/userinfo/password",
        area:["500px","500px"]
    })
}
function logout() {
    layer.confirm('确定退出系统吗？',{icon:3,title:"询问"},function (index) {
        ajax.post("/logout").then(()=>{
            layer.alert('再见！',{icon:6},function () {
                location.replace("/")
            });
        })
        layer.close(index);
    })
}
</script>
</body>
</html>
